package com.cdxy.dmr.repository;

import com.cdxy.dmr.dataObject.HotelDO;
import com.cdxy.dmr.mapper.HotelMapper;
import com.cdxy.model.dto.base.mybatis.BaseRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * <p>
 * 酒店表 服务实现类
 * </p>
 *
 * @author autoGenCode
 * @since 2020-03-05
 */
@Repository
public class HotelRepository extends BaseRepository<HotelMapper, HotelDO> {
    /**
     * 查询热门酒店
     *
     * @param size
     * @return
     */
    public List<HotelDO> listBySizeOrderBySearchNum(Integer size) {
        return this.baseMapper.selectList(this.queryWrapper()
                .orderByDesc(HotelDO::getSearchNum)
                .last("LIMIT " + size));
    }

    /**
     * 查询热门酒店
     *
     * @param city
     * @param size
     * @return
     */
    public List<HotelDO> listByCityBySizeOrderBySearchNum(String city, Integer size) {
        return this.baseMapper.selectList(this.queryWrapper()
                .eq(HotelDO::getCity, city)
                .orderByDesc(HotelDO::getSearchNum)
                .last("LIMIT " + size));
    }

    /**
     * 更新搜索次数
     *
     * @param idList
     * @return
     */
    public boolean updateSearchNum(List<Integer> idList) {
        return this.baseMapper.updateSearchNum(idList);
    }

    /**
     * 更新搜索次数
     *
     * @param id
     * @return
     */
    public boolean updateSearchNum(Integer id) {
        return this.baseMapper.updateSearchNumOne(id);
    }

}
